package com.hudongwx.yuan_sdjj.activity;

import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hudongwx.yuan_sdjj.R;
import com.hudongwx.yuan_sdjj.fragment.GoodFragment;
import com.hudongwx.yuan_sdjj.fragment.HomeFragment;
import com.hudongwx.yuan_sdjj.fragment.HotFragment;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity  {
    String TAG="MainActivity";
    @ViewInject(android.R.id.tabhost)
    FragmentTabHost fragmentTabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        Log.i(TAG, "onCreatehkjgk: "+(fragmentTabHost==null));
        fragmentTabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("home").setIndicator(getTab("闪降",R.drawable.selector_tab_1)),HomeFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("hot").setIndicator(getTab("预热",R.drawable.selector_tab_2)), HotFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("good").setIndicator(getTab("聚赞",R.drawable.selector_tab_3)),GoodFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("shopping").setIndicator(getTab("购物车",R.drawable.selector_tab_4)),HomeFragment.class,null);
        fragmentTabHost.addTab(fragmentTabHost.newTabSpec("mine").setIndicator(getTab("我的",R.drawable.selector_tab_5)),HomeFragment.class,null);
    }

    /**
     * 设置tab的样式
     * @param name
     * @param img
     * @return
     */
    public View getTab(String name,int img){
        Log.i(TAG, "getTab: "+name);
        View view = getLayoutInflater().inflate(R.layout.tab_host, null);
        TextView tv= (TextView) view.findViewById(R.id.tab_tv_1);
        tv.setTextSize(11);
        tv.setPadding(0,0,0,3);
        ImageView iv = (ImageView) view.findViewById(R.id.tab_iv_1);
        tv.setText(name);
        iv.setImageResource(img);
        return view;

    }


}
